<template>
    <div style="padding:20px 20px 20px 20px;background:#fff;">
      <el-table :data="list.slice((currentPage-1)*pagesize,currentPage*pagesize)" style="width: 100%"
        row-key="id" border lazy :load="load">
        <el-table-column prop="name" label="项目名称" align="center"></el-table-column>
        <el-table-column prop="fee" label="手工费" align="center"></el-table-column>
        <el-table-column prop="addtime" label="添加日期" align="center"></el-table-column>
        <el-table-column
            fixed="right"
            label="操作"
            width="120" align="center">
          <template slot-scope="scope">
            <el-tooltip class="item smallinit" effect="dark" content="使用物品" placement="top-start">
              <el-button size="small" type="warning" icon="el-icon-s-data" 
              @click="dialog('goodsTable',scope.row.goods)"></el-button>
            </el-tooltip>
            <!--<el-button @click="dialog('cardEdit',scope.row)" class="smallinit" type="primary" 
            icon="el-icon-edit" size="small"></el-button>-->
            <el-popconfirm title="确定要删除当前数据吗" @confirm="del(scope.row.id,scope)">
                <el-button type="danger" size="small" class="smallinit" icon="el-icon-delete" slot="reference"
                ></el-button>
            </el-popconfirm>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        class="fen"
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-size="pagesize"
        :page-sizes="[5, 10, 20, 50]"      
        layout="total, sizes, prev, pager, next, jumper"
        :total="list.length">
      </el-pagination>
</div>
</template>
<script>
export default {
  name: 'cardTable',
  props:['list'],
  data(){
      return {
          currentPage:1, //初始页
          pagesize:10, //每页的数据
          show_page:true,
          nowpage:1,
          maxpage:10
      }
  },
  created: function() {
    
  },
  methods: {
    handleSizeChange: function (size) {
        this.pagesize = size;
    },
    handleCurrentChange: function(currentPage){
      this.currentPage = currentPage;
    },
    changeLeft($event){
        $event.currentTarget.className="active";
    },
    removeLeft($event){
        $event.currentTarget.className ="tdclass";
    },
    load(tree, treeNode, resolve) {
      setTimeout(() => {
        resolve()
      }, 1000)
    },
    dialog:function(key,item){
      this.$emit("func",{'key':key,'item':item})
    },
    del:function(id,scope){
      var index = scope.$index
      var that = this
      this.$del('manage/card/del',{id:id}).then((res) => {
        if(res.code == 1){
            that.$message.success('删除成功!!');
            that.list.splice(index,1)
        }else{
          that.$message.error('删除失败!!');
        }
      })
    }
  }
};
</script>
<style>
.fen{text-align:center;}

.el-button+.el-button {
    margin-left: 3px !important;
}
.smallinit {
    padding: 2px 4px !important;
}
</style>